# 请求工具类
import json
import requests
import share

class requestUtil:
    # api:api请求地址  method:请求类型  jsonStr:请求参数
    def __init__(self, api, method, jsonStr=None):
        url = share.RURL.backendUrl + api
        requests.encoding = 'utf-8'
        if method == "POST":
            result = requests.request(method="POST", url=url, json=jsonStr, headers=share.token.headers)
        elif method == "GET":
            result = requests.request(method="GET", url=url, headers=share.token.headers)
        elif method == "PUT":
            result = requests.request(method="PUT", url=url, json=jsonStr, headers=share.token.headers)
        elif method == "DELETE":
            result = requests.request(method="DELETE", url=url, headers=share.token.headers)
        dataMap = json.loads(result.text, strict=False)
        self.dataMap = dataMap
